/**
 * @copyright (c) 2003 - 2022, Goodix Co., Ltd. All rights reserved.
 *
 * @file    gh3x2x_demo_algo_memory.h
 *
 * @brief   gh3x2x algo memory set
 *
 * @version ref gh3x2x_demo_algo_memory.h
 *
 */
#ifndef _GH3X2X_DEMO_ALGO_MEMORY_H_
#define _GH3X2X_DEMO_ALGO_MEMORY_H_

#include "gh3x2x_demo_algo_call.h"
#include "gh3x2x_demo_algo_config.h"

#if (__GOODIX_ALGO_CALL_MODE__)

/* algorithm run mode:simultaneously or not */
#define GH3X2X_ALGORITHM_RUN_ALONE                  (0)             /**< only excute one algorithm at the same time */
#define GH3X2X_ALGORITHM_RUN_SIMULTANEOUSLY         (1)             /**< excute more than one algorithm */

/* algorithm mem size in byte */
#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_1CHNL       (7984)       /**< HB 1 chnl algorithm peak memory size in byte */
#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_2CHNL       (9116)       /**< HB 2 chnl  algorithm peak memory size in byte */
#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_3CHNL       (10248)       /**< HB 3 chnl  algorithm peak memory size in byte */
#define GH3X2X_HR_ALGORITHM_MEMORY_PEAK_4CHNL       (11380)       /**< HB 4 chnl  algorithm peak memory size in byte */

#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_1CHNL   (2988)       /**< HB 1 chnl  algorithm desident memory size in byte */
#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_2CHNL   (4120)       /**< HB 2 chnl  algorithm desident memory size in byte */
#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_3CHNL   (5252)       /**< HB 3 chnl  algorithm desident memory size in byte */
#define GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_4CHNL   (6384)       /**< HB 4 chnl  algorithm desident memory size in byte */

#define GH3X2X_HR_ALGORITHM_MEMORY_REDUNDANCY       (1000)



#define GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_1CHNL     (10532)       /**< SPO2 1 chnl  algorithm peak memory size in byte */
#define GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_2CHNL     (17608)       /**< SPO2 2 chnl  algorithm peak memory size in byte */
#define GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_3CHNL     (24684)       /**< SPO2 3 chnl  algorithm peak memory size in byte */
#define GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_4CHNL     (31260)       /**< SPO2 4 chnl  algorithm peak memory size in byte */

#define GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_1CHNL (6916)        /**< SPO2 1 chnl  algorithm memory size in byte */
#define GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_2CHNL (13720)       /**< SPO2 2 chnl  algorithm memory size in byte */
#define GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_3CHNL (20524)       /**< SPO2 3 chnl  algorithm memory size in byte */
#define GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_4CHNL (27328)       /**< SPO2 4 chnl  algorithm memory size in byte */

#define GH3X2X_SPO2_ALGORITHM_MEMORY_REDUNDANCY     (1000)


#define GH3X2X_ECG_ALGORITHM_MEMORY_PEAK            (25764)       /**< ECG algorithm peak memory size in byte */
#define GH3X2X_ECG_ALGORITHM_MEMORY_RESIDENT        (25764)       /**< ECG algorithm resident memory size in byte */
#define GH3X2X_ECG_ALGORITHM_MEMORY_REDUNDANCY      (1000)


#define GH3X2X_HRV_ALGORITHM_MEMORY_PEAK            (2856)        /**< HRV algorithm peak memory size in byte */
#define GH3X2X_HRV_ALGORITHM_MEMORY_RESIDENT        (2856)        /**< HRV algorithm resident memory size in byte */
#define GH3X2X_HRV_ALGORITHM_MEMORY_REDUNDANCY      (300)


#define GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_PEAK       (800)          /**< SOFT ADT algorithm peak memory size in byte */
#define GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_RESIDENT   (0)          /**< SOFT ADT algorithm resident memory size in byte */
#define GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_REDUNDANCY (80)        /**< SOFT ADT algorithm redundancy memory size in byte */


#define GH3X2X_HSM_ALGORITHM_MEMORY_PEAK            (944)       /**< HSM algorithm memory peak size in byte */
#define GH3X2X_HSM_ALGORITHM_MEMORY_RESIDENT        (944)       /**< HSM algorithm memory resident size in byte */
#define GH3X2X_HSM_ALGORITHM_MEMORY_REDUNDANCY      (100)


#define GH3X2X_BT_ALGORITHM_MEMORY_PEAK             (1600)        /**< BT algorithm memory peak size in byte */
#define GH3X2X_BT_ALGORITHM_MEMORY_RESIDENT         (1500)        /**< BT algorithm memory resident size in byte */
#define GH3X2X_BT_ALGORITHM_MEMORY_REDUNDANCY       (200)


#define GH3X2X_RESP_ALGORITHM_MEMORY_PEAK           (5435)        /**< RESP algorithm memory peak size in byte */
#define GH3X2X_RESP_ALGORITHM_MEMORY_RESIDENT       (2363)        /**< RESP algorithm memory resident size in byte */
#define GH3X2X_RESP_ALGORITHM_MEMORY_REDUNDANCY     (500)


#define GH3X2X_AF_ALGORITHM_MEMORY_PEAK             (3262)        /**< AF algorithm memory peak size in byte */
#define GH3X2X_AF_ALGORITHM_MEMORY_RESIDENT         (1102)        /**< AF algorithm memory resident size in byte */
#define GH3X2X_AF_ALGORITHM_MEMORY_REDUNDANCY       (300)

#define GH3X2X_BP_ALGORITHM_MEMORY_PEAK             (0)  /**< FPBP algorithm memory peak size in byte */
#define GH3X2X_BP_ALGORITHM_MEMORY_RESIDENT         (0)  /**< FPBP algorithm memory resident size in byte */
#define GH3X2X_BP_ALGORITHM_MEMORY_REDUNDANCY       (0)


/* algorithm mem config */
#if (__GOODIX_ALGO_CALL_MODE__)

#if (__USE_GOODIX_HR_ALGORITHM__)
#if __HR_ALGORITHM_SUPPORT_CHNL_NUM__ <= 1
#define   GH3X2X_ALGORITHM_HR_MEMORY_PEAK      GH3X2X_HR_ALGORITHM_MEMORY_PEAK_1CHNL
#define   GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT  GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_1CHNL 
#elif __HR_ALGORITHM_SUPPORT_CHNL_NUM__ == 2
#define   GH3X2X_ALGORITHM_HR_MEMORY_PEAK   GH3X2X_HR_ALGORITHM_MEMORY_PEAK_2CHNL
#define   GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT  GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_2CHNL 
#elif __HR_ALGORITHM_SUPPORT_CHNL_NUM__ == 3
#define   GH3X2X_ALGORITHM_HR_MEMORY_PEAK   GH3X2X_HR_ALGORITHM_MEMORY_PEAK_3CHNL
#define   GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT  GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_3CHNL 
#elif __HR_ALGORITHM_SUPPORT_CHNL_NUM__ >= 4
#define   GH3X2X_ALGORITHM_HR_MEMORY_PEAK   GH3X2X_HR_ALGORITHM_MEMORY_PEAK_4CHNL
#define   GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT  GH3X2X_HR_ALGORITHM_MEMORY_RESIDENT_4CHNL 
#endif
#define GH3X2X_ALGORITHM_HR_MEMORY_PEAK_WITHOUT_RESIDENT    (GH3X2X_ALGORITHM_HR_MEMORY_PEAK - GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_HR_MEMORY_REDUNDANCY                 GH3X2X_HR_ALGORITHM_MEMORY_REDUNDANCY
#else
#define GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT   (0)
#define GH3X2X_ALGORITHM_HR_MEMORY_PEAK_WITHOUT_RESIDENT    (0)
#define GH3X2X_ALGORITHM_HR_MEMORY_REDUNDANCY               (0)
#endif

#if (__USE_GOODIX_HSM_ALGORITHM__)
#define   GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT   (GH3X2X_HSM_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_HSM_MEMORY_PEAK_WITHOUT_RESIDENT    (GH3X2X_HSM_ALGORITHM_MEMORY_PEAK - GH3X2X_HSM_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_HSM_MEMORY_REDUNDANCY                GH3X2X_HSM_ALGORITHM_MEMORY_REDUNDANCY
#else
#define GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT   (0)
#define GH3X2X_ALGORITHM_HSM_MEMORY_PEAK_WITHOUT_RESIDENT    (0)
#define GH3X2X_ALGORITHM_HSM_MEMORY_REDUNDANCY               (0)
#endif

#if (__USE_GOODIX_SPO2_ALGORITHM__)
#if __SPO2_ALGORITHM_SUPPORT_CHNL_NUM__ <= 1
#define   GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK      GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_1CHNL
#define   GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT  GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_1CHNL 
#elif __SPO2_ALGORITHM_SUPPORT_CHNL_NUM__ == 2
#define   GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK   GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_2CHNL
#define   GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT  GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_2CHNL 
#elif __SPO2_ALGORITHM_SUPPORT_CHNL_NUM__ == 3
#define   GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK   GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_3CHNL
#define   GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT  GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_3CHNL 
#elif __SPO2_ALGORITHM_SUPPORT_CHNL_NUM__ >= 4
#define   GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK   GH3X2X_SPO2_ALGORITHM_MEMORY_PEAK_4CHNL
#define   GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT  GH3X2X_SPO2_ALGORITHM_MEMORY_RESIDENT_4CHNL 
#endif
#define GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK_WITHOUT_RESIDENT    (GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK - GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_SPO2_MEMORY_REDUNDANCY                 GH3X2X_SPO2_ALGORITHM_MEMORY_REDUNDANCY
#else
#define GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT   (0)
#define GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK_WITHOUT_RESIDENT    (0)
#define GH3X2X_ALGORITHM_SPO2_MEMORY_REDUNDANCY                (0)

#endif

#if (__USE_GOODIX_ECG_ALGORITHM__)
#define   GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT   (GH3X2X_ECG_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_ECG_MEMORY_PEAK_WITHOUT_RESIDENT    (GH3X2X_ECG_ALGORITHM_MEMORY_PEAK - GH3X2X_ECG_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_ECG_MEMORY_REDUNDANCY                GH3X2X_ECG_ALGORITHM_MEMORY_REDUNDANCY
#else
#define GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT   (0)
#define GH3X2X_ALGORITHM_ECG_MEMORY_PEAK_WITHOUT_RESIDENT    (0)
#define GH3X2X_ALGORITHM_ECG_MEMORY_REDUNDANCY                (0)
#endif

#if (__USE_GOODIX_HRV_ALGORITHM__)
#define   GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT   (GH3X2X_HRV_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_HRV_MEMORY_PEAK_WITHOUT_RESIDENT    (GH3X2X_HRV_ALGORITHM_MEMORY_PEAK - GH3X2X_HRV_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_HRV_MEMORY_REDUNDANCY                GH3X2X_HRV_ALGORITHM_MEMORY_REDUNDANCY
#else
#define GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT   (0)
#define GH3X2X_ALGORITHM_HRV_MEMORY_PEAK_WITHOUT_RESIDENT    (0)
#define GH3X2X_ALGORITHM_HRV_MEMORY_REDUNDANCY               (0)
#endif

#if (__USE_GOODIX_BT_ALGORITHM__)
#define   GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT   (GH3X2X_BT_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_BT_MEMORY_PEAK_WITHOUT_RESIDENT    (GH3X2X_BT_ALGORITHM_MEMORY_PEAK - GH3X2X_BT_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_BT_MEMORY_REDUNDANCY                GH3X2X_BT_ALGORITHM_MEMORY_REDUNDANCY
#else
#define GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT   (0)
#define GH3X2X_ALGORITHM_BT_MEMORY_PEAK_WITHOUT_RESIDENT    (0)
#define GH3X2X_ALGORITHM_BT_MEMORY_REDUNDANCY               (0)
#endif

#if (__USE_GOODIX_RESP_ALGORITHM__)
#define   GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT   (GH3X2X_RESP_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_RESP_MEMORY_PEAK_WITHOUT_RESIDENT    (GH3X2X_RESP_ALGORITHM_MEMORY_PEAK - GH3X2X_RESP_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_RESP_MEMORY_REDUNDANCY                GH3X2X_RESP_ALGORITHM_MEMORY_REDUNDANCY
#else
#define GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT   (0)
#define GH3X2X_ALGORITHM_RESP_MEMORY_PEAK_WITHOUT_RESIDENT    (0)
#define GH3X2X_ALGORITHM_RESP_MEMORY_REDUNDANCY               (0)
#endif

#if (__USE_GOODIX_AF_ALGORITHM__)
#define   GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT   (GH3X2X_AF_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_AF_MEMORY_PEAK_WITHOUT_RESIDENT    (GH3X2X_AF_ALGORITHM_MEMORY_PEAK - GH3X2X_AF_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_AF_MEMORY_REDUNDANCY                GH3X2X_AF_ALGORITHM_MEMORY_REDUNDANCY
#else
#define GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT   (0)
#define GH3X2X_ALGORITHM_AF_MEMORY_PEAK_WITHOUT_RESIDENT    (0)
#define GH3X2X_ALGORITHM_AF_MEMORY_REDUNDANCY               (0)
#endif


#if (__USE_GOODIX_SOFT_ADT_ALGORITHM__)
#define   GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT   (GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT    (GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_PEAK - GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY                GH3X2X_SOFT_ADT_ALGORITHM_MEMORY_REDUNDANCY
#else
#define GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT   (0)
#define GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT    (0)
#define GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY                (0)
#endif

#if (__USE_GOODIX_BP_ALGORITHM__)
#define   GH3X2X_ALGORITHM_BP_MEMORY_RESIDENT   (GH3X2X_BP_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_BP_MEMORY_PEAK_WITHOUT_RESIDENT    (GH3X2X_BP_ALGORITHM_MEMORY_PEAK - GH3X2X_BP_ALGORITHM_MEMORY_RESIDENT)
#define GH3X2X_ALGORITHM_BP_MEMORY_REDUNDANCY                GH3X2X_BP_ALGORITHM_MEMORY_REDUNDANCY
#else
#define GH3X2X_ALGORITHM_BP_MEMORY_RESIDENT   (0)
#define GH3X2X_ALGORITHM_BP_MEMORY_PEAK_WITHOUT_RESIDENT    (0)
#define GH3X2X_ALGORITHM_BP_MEMORY_REDUNDANCY                (0)
#endif

#endif



#if (__ALGO_RUN_SIMULTANEOUSLY_SUPPORT__ == SUPPORT_NO_MULTI_ALGORITHM)

#define GH3X2X_ALGORITHMS_MEMORY_SIZE (0)
#if __USE_GOODIX_HR_ALGORITHM__
#if (GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT + GH3X2X_ALGORITHM_HR_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_HR_MEMORY_REDUNDANCY) > GH3X2X_ALGORITHMS_MEMORY_SIZE
#undef GH3X2X_ALGORITHMS_MEMORY_SIZE
#define GH3X2X_ALGORITHMS_MEMORY_SIZE (GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT + GH3X2X_ALGORITHM_HR_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_HR_MEMORY_REDUNDANCY)
#endif
#endif
#if __USE_GOODIX_SOFT_ADT_ALGORITHM__     //hr and soft is running at same time
#undef GH3X2X_ALGORITHMS_MEMORY_SIZE
#define GH3x2x_TEMP_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_HR_MEMORY_PEAK_WITHOUT_RESIDENT
#if GH3x2x_TEMP_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3x2x_TEMP_PEAK_WITHOUT_RESIDENT
#define GH3x2x_TEMP_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#define GH3x2x_TEMP_REDUNDANCY GH3X2X_ALGORITHM_HR_MEMORY_REDUNDANCY
#if GH3x2x_TEMP_REDUNDANCY < GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY
#undef GH3x2x_TEMP_REDUNDANCY
#define GH3x2x_TEMP_REDUNDANCY GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY
#endif
#define GH3X2X_ALGORITHMS_MEMORY_SIZE (GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT + GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT + GH3x2x_TEMP_PEAK_WITHOUT_RESIDENT + GH3x2x_TEMP_REDUNDANCY)
#endif
#if __USE_GOODIX_SPO2_ALGORITHM__
#if (GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT + GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_SPO2_MEMORY_REDUNDANCY) > GH3X2X_ALGORITHMS_MEMORY_SIZE
#undef GH3X2X_ALGORITHMS_MEMORY_SIZE
#define GH3X2X_ALGORITHMS_MEMORY_SIZE (GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT + GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_SPO2_MEMORY_REDUNDANCY)
#endif
#endif

#if __USE_GOODIX_HRV_ALGORITHM__
#if (GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT + GH3X2X_ALGORITHM_HRV_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_HRV_MEMORY_REDUNDANCY) > GH3X2X_ALGORITHMS_MEMORY_SIZE
#undef GH3X2X_ALGORITHMS_MEMORY_SIZE
#define GH3X2X_ALGORITHMS_MEMORY_SIZE (GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT + GH3X2X_ALGORITHM_HRV_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_HRV_MEMORY_REDUNDANCY)
#endif
#endif
#if __USE_GOODIX_ECG_ALGORITHM__
#if (GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT + GH3X2X_ALGORITHM_ECG_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_ECG_MEMORY_REDUNDANCY) > GH3X2X_ALGORITHMS_MEMORY_SIZE
#undef GH3X2X_ALGORITHMS_MEMORY_SIZE
#define GH3X2X_ALGORITHMS_MEMORY_SIZE (GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT + GH3X2X_ALGORITHM_ECG_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_ECG_MEMORY_REDUNDANCY)
#endif
#endif
#if __USE_GOODIX_HSM_ALGORITHM__
#if (GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT + GH3X2X_ALGORITHM_HSM_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_HSM_MEMORY_REDUNDANCY) > GH3X2X_ALGORITHMS_MEMORY_SIZE
#undef GH3X2X_ALGORITHMS_MEMORY_SIZE
#define GH3X2X_ALGORITHMS_MEMORY_SIZE (GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT + GH3X2X_ALGORITHM_HSM_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_HSM_MEMORY_REDUNDANCY)
#endif
#endif
#if __USE_GOODIX_BT_ALGORITHM__
#if (GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT + GH3X2X_ALGORITHM_BT_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_BT_MEMORY_REDUNDANCY) > GH3X2X_ALGORITHMS_MEMORY_SIZE
#undef GH3X2X_ALGORITHMS_MEMORY_SIZE
#define GH3X2X_ALGORITHMS_MEMORY_SIZE (GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT + GH3X2X_ALGORITHM_BT_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_BT_MEMORY_REDUNDANCY)
#endif
#endif
#if __USE_GOODIX_RESP_ALGORITHM__
#if (GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT + GH3X2X_ALGORITHM_RESP_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_RESP_MEMORY_REDUNDANCY) > GH3X2X_ALGORITHMS_MEMORY_SIZE
#undef GH3X2X_ALGORITHMS_MEMORY_SIZE
#define GH3X2X_ALGORITHMS_MEMORY_SIZE (GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT + GH3X2X_ALGORITHM_RESP_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_RESP_MEMORY_REDUNDANCY)
#endif
#endif
#if __USE_GOODIX_AF_ALGORITHM__
#if (GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT + GH3X2X_ALGORITHM_AF_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_AF_MEMORY_REDUNDANCY) > GH3X2X_ALGORITHMS_MEMORY_SIZE
#undef GH3X2X_ALGORITHMS_MEMORY_SIZE
#define GH3X2X_ALGORITHMS_MEMORY_SIZE (GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT + GH3X2X_ALGORITHM_AF_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_AF_MEMORY_REDUNDANCY)
#endif
#endif
#if __USE_GOODIX_SOFT_ADT_ALGORITHM__
#if (GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT + GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY) > GH3X2X_ALGORITHMS_MEMORY_SIZE
#undef GH3X2X_ALGORITHMS_MEMORY_SIZE
#define GH3X2X_ALGORITHMS_MEMORY_SIZE (GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT + GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY)
#endif
#endif
#if __USE_GOODIX_BP_ALGORITHM__
#if (GH3X2X_ALGORITHM_BP_MEMORY_RESIDENT + GH3X2X_ALGORITHM_BP_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_BP_MEMORY_REDUNDANCY) > GH3X2X_ALGORITHMS_MEMORY_SIZE
#undef GH3X2X_ALGORITHMS_MEMORY_SIZE
#define GH3X2X_ALGORITHMS_MEMORY_SIZE (GH3X2X_ALGORITHM_BP_MEMORY_RESIDENT + GH3X2X_ALGORITHM_BP_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHM_BP_MEMORY_REDUNDANCY)
#endif
#endif

#define GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL  ( ((GU32)((GH3X2X_ALGORITHMS_MEMORY_SIZE  + 3)/4))*4)
#endif

#if (__ALGO_RUN_SIMULTANEOUSLY_SUPPORT__ == SUPPORT_MULTI_ALGORITHM)

#define   GH3X2X_ALGORITHMS_MEMORY_RESIDENT    ((__USE_GOODIX_HR_ALGORITHM__ * GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT) + \
                                                (__USE_GOODIX_SPO2_ALGORITHM__ * GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT) + \
                                                (__USE_GOODIX_ECG_ALGORITHM__ * GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT) + \
                                                (__USE_GOODIX_HRV_ALGORITHM__ * GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT) + \
                                                (__USE_GOODIX_HSM_ALGORITHM__ * GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT) + \
                                                (__USE_GOODIX_BT_ALGORITHM__ * GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT) + \
                                                (__USE_GOODIX_RESP_ALGORITHM__ * GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT) + \
                                                (__USE_GOODIX_AF_ALGORITHM__ * GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT) + \
                                                (__USE_GOODIX_SOFT_ADT_ALGORITHM__ * GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT) + \
                                                (__USE_GOODIX_BP_ALGORITHM__ * GH3X2X_ALGORITHM_BP_MEMORY_RESIDENT))
//resident
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT  (0)
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_HR_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_HR_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_ECG_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_ECG_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_HRV_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_HRV_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_HSM_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_HSM_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_BT_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_BT_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_RESP_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_RESP_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_AF_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_AF_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT
#endif

//redundancy
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY (0)
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_HR_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_HR_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_SPO2_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_SPO2_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_ECG_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_ECG_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_HRV_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_HRV_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_HSM_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_HSM_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_BT_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_BT_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_RESP_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_RESP_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_AF_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_AF_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY
#endif

//final size
#define GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL  ( ((GU32)((GH3X2X_ALGORITHMS_MEMORY_RESIDENT + GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY + 3)/4))*4)                                     

#endif

#if (__ALGO_RUN_SIMULTANEOUSLY_SUPPORT__ == SUPPORT_GROUP_MULTI_ALGORITHM)

#define   GH3X2X_ALGORITHMS_MEMORY_RESIDENT_0  (((0 != (GH3X2X_ALGO_FUNCTION_GROUP_0 & GH3X2X_FUNCTION_HR)) * __USE_GOODIX_HR_ALGORITHM__ * GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_0 & GH3X2X_FUNCTION_SPO2)) * __USE_GOODIX_SPO2_ALGORITHM__ * GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_0 & GH3X2X_FUNCTION_ECG)) * __USE_GOODIX_ECG_ALGORITHM__ * GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_0 & GH3X2X_FUNCTION_HRV)) * __USE_GOODIX_HRV_ALGORITHM__ * GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_0 & GH3X2X_FUNCTION_HSM)) * __USE_GOODIX_HSM_ALGORITHM__ * GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_0 & GH3X2X_FUNCTION_BT)) * __USE_GOODIX_BT_ALGORITHM__ * GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_0 & GH3X2X_FUNCTION_RESP)) * __USE_GOODIX_RESP_ALGORITHM__ * GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_0 & GH3X2X_FUNCTION_AF)) * __USE_GOODIX_AF_ALGORITHM__ * GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_0 & (GH3X2X_FUNCTION_SOFT_ADT_GREEN|GH3X2X_FUNCTION_SOFT_ADT_IR))) * __USE_GOODIX_SOFT_ADT_ALGORITHM__ * GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_0 & (GH3X2X_FUNCTION_FPBP|GH3X2X_FUNCTION_PWA))) * __USE_GOODIX_BP_ALGORITHM__ * GH3X2X_ALGORITHM_BP_MEMORY_RESIDENT))

#define   GH3X2X_ALGORITHMS_MEMORY_RESIDENT_1  (((0 != (GH3X2X_ALGO_FUNCTION_GROUP_1 & GH3X2X_FUNCTION_HR)) * __USE_GOODIX_HR_ALGORITHM__ * GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_1 & GH3X2X_FUNCTION_SPO2)) * __USE_GOODIX_SPO2_ALGORITHM__ * GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_1 & GH3X2X_FUNCTION_ECG)) * __USE_GOODIX_ECG_ALGORITHM__ * GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_1 & GH3X2X_FUNCTION_HRV)) * __USE_GOODIX_HRV_ALGORITHM__ * GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_1 & GH3X2X_FUNCTION_HSM)) * __USE_GOODIX_HSM_ALGORITHM__ * GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_1 & GH3X2X_FUNCTION_BT)) * __USE_GOODIX_BT_ALGORITHM__ * GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_1 & GH3X2X_FUNCTION_RESP)) * __USE_GOODIX_RESP_ALGORITHM__ * GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_1 & GH3X2X_FUNCTION_AF)) * __USE_GOODIX_AF_ALGORITHM__ * GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_1 & (GH3X2X_FUNCTION_SOFT_ADT_GREEN|GH3X2X_FUNCTION_SOFT_ADT_IR))) * __USE_GOODIX_SOFT_ADT_ALGORITHM__ * GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_1 & (GH3X2X_FUNCTION_FPBP|GH3X2X_FUNCTION_PWA))) * __USE_GOODIX_BP_ALGORITHM__ * GH3X2X_ALGORITHM_BP_MEMORY_RESIDENT))

#define   GH3X2X_ALGORITHMS_MEMORY_RESIDENT_2  (((0 != (GH3X2X_ALGO_FUNCTION_GROUP_2 & GH3X2X_FUNCTION_HR)) * __USE_GOODIX_HR_ALGORITHM__ * GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_2 & GH3X2X_FUNCTION_SPO2)) * __USE_GOODIX_SPO2_ALGORITHM__ * GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_2 & GH3X2X_FUNCTION_ECG)) * __USE_GOODIX_ECG_ALGORITHM__ * GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_2 & GH3X2X_FUNCTION_HRV)) * __USE_GOODIX_HRV_ALGORITHM__ * GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_2 & GH3X2X_FUNCTION_HSM)) * __USE_GOODIX_HSM_ALGORITHM__ * GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_2 & GH3X2X_FUNCTION_BT)) * __USE_GOODIX_BT_ALGORITHM__ * GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_2 & GH3X2X_FUNCTION_RESP)) * __USE_GOODIX_RESP_ALGORITHM__ * GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_2 & GH3X2X_FUNCTION_AF)) * __USE_GOODIX_AF_ALGORITHM__ * GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_2 & (GH3X2X_FUNCTION_SOFT_ADT_GREEN|GH3X2X_FUNCTION_SOFT_ADT_IR))) * __USE_GOODIX_SOFT_ADT_ALGORITHM__ * GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_2 & (GH3X2X_FUNCTION_FPBP|GH3X2X_FUNCTION_PWA))) * __USE_GOODIX_BP_ALGORITHM__ * GH3X2X_ALGORITHM_BP_MEMORY_RESIDENT))

#define   GH3X2X_ALGORITHMS_MEMORY_RESIDENT_3  (((0 != (GH3X2X_ALGO_FUNCTION_GROUP_3 & GH3X2X_FUNCTION_HR)) * __USE_GOODIX_HR_ALGORITHM__ * GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_3 & GH3X2X_FUNCTION_SPO2)) * __USE_GOODIX_SPO2_ALGORITHM__ * GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_3 & GH3X2X_FUNCTION_ECG)) * __USE_GOODIX_ECG_ALGORITHM__ * GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_3 & GH3X2X_FUNCTION_HRV)) * __USE_GOODIX_HRV_ALGORITHM__ * GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_3 & GH3X2X_FUNCTION_HSM)) * __USE_GOODIX_HSM_ALGORITHM__ * GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_3 & GH3X2X_FUNCTION_BT)) * __USE_GOODIX_BT_ALGORITHM__ * GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_3 & GH3X2X_FUNCTION_RESP)) * __USE_GOODIX_RESP_ALGORITHM__ * GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_3 & GH3X2X_FUNCTION_AF)) * __USE_GOODIX_AF_ALGORITHM__ * GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_3 & (GH3X2X_FUNCTION_SOFT_ADT_GREEN|GH3X2X_FUNCTION_SOFT_ADT_IR))) * __USE_GOODIX_SOFT_ADT_ALGORITHM__ * GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_3 & (GH3X2X_FUNCTION_FPBP|GH3X2X_FUNCTION_PWA))) * __USE_GOODIX_BP_ALGORITHM__ * GH3X2X_ALGORITHM_BP_MEMORY_RESIDENT))

#define   GH3X2X_ALGORITHMS_MEMORY_RESIDENT_4  (((0 != (GH3X2X_ALGO_FUNCTION_GROUP_4 & GH3X2X_FUNCTION_HR)) * __USE_GOODIX_HR_ALGORITHM__ * GH3X2X_ALGORITHM_HR_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_4 & GH3X2X_FUNCTION_SPO2)) * __USE_GOODIX_SPO2_ALGORITHM__ * GH3X2X_ALGORITHM_SPO2_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_4 & GH3X2X_FUNCTION_ECG)) * __USE_GOODIX_ECG_ALGORITHM__ * GH3X2X_ALGORITHM_ECG_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_4 & GH3X2X_FUNCTION_HRV)) * __USE_GOODIX_HRV_ALGORITHM__ * GH3X2X_ALGORITHM_HRV_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_4 & GH3X2X_FUNCTION_HSM)) * __USE_GOODIX_HSM_ALGORITHM__ * GH3X2X_ALGORITHM_HSM_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_4 & GH3X2X_FUNCTION_BT)) * __USE_GOODIX_BT_ALGORITHM__ * GH3X2X_ALGORITHM_BT_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_4 & GH3X2X_FUNCTION_RESP)) * __USE_GOODIX_RESP_ALGORITHM__ * GH3X2X_ALGORITHM_RESP_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_4 & GH3X2X_FUNCTION_AF)) * __USE_GOODIX_AF_ALGORITHM__ * GH3X2X_ALGORITHM_AF_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_4 & (GH3X2X_FUNCTION_SOFT_ADT_GREEN|GH3X2X_FUNCTION_SOFT_ADT_IR))) * __USE_GOODIX_SOFT_ADT_ALGORITHM__ * GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_RESIDENT) + \
                                                ((0 != (GH3X2X_ALGO_FUNCTION_GROUP_4 & (GH3X2X_FUNCTION_FPBP|GH3X2X_FUNCTION_PWA))) * __USE_GOODIX_BP_ALGORITHM__ * GH3X2X_ALGORITHM_BP_MEMORY_RESIDENT))


//resident
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT  (0)
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_HR_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_HR_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_SPO2_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_ECG_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_ECG_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_HRV_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_HRV_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_HSM_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_HSM_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_BT_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_BT_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_RESP_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_RESP_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_AF_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_AF_MEMORY_PEAK_WITHOUT_RESIDENT
#endif
#if GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT < GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT
#undef GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_PEAK_WITHOUT_RESIDENT
#endif

//redundancy
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY  (0)
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_HR_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_HR_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_SPO2_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_SPO2_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_ECG_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_ECG_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_HRV_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_HRV_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_HSM_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_HSM_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_BT_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_BT_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_RESP_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_RESP_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_AF_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_AF_MEMORY_REDUNDANCY
#endif
#if GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY < GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY
#undef GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY
#define GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY GH3X2X_ALGORITHM_SOFT_ADT_MEMORY_REDUNDANCY
#endif

//memory resident
#define GH3X2X_ALGORITHMS_MEMORY_RESIDENT  (0)
#if GH3X2X_ALGORITHMS_MEMORY_RESIDENT < GH3X2X_ALGORITHMS_MEMORY_RESIDENT_0
#undef GH3X2X_ALGORITHMS_MEMORY_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_RESIDENT GH3X2X_ALGORITHMS_MEMORY_RESIDENT_0
#endif
#if GH3X2X_ALGORITHMS_MEMORY_RESIDENT < GH3X2X_ALGORITHMS_MEMORY_RESIDENT_1
#undef GH3X2X_ALGORITHMS_MEMORY_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_RESIDENT GH3X2X_ALGORITHMS_MEMORY_RESIDENT_1
#endif
#if GH3X2X_ALGORITHMS_MEMORY_RESIDENT < GH3X2X_ALGORITHMS_MEMORY_RESIDENT_2
#undef GH3X2X_ALGORITHMS_MEMORY_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_RESIDENT GH3X2X_ALGORITHMS_MEMORY_RESIDENT_2
#endif
#if GH3X2X_ALGORITHMS_MEMORY_RESIDENT < GH3X2X_ALGORITHMS_MEMORY_RESIDENT_3
#undef GH3X2X_ALGORITHMS_MEMORY_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_RESIDENT GH3X2X_ALGORITHMS_MEMORY_RESIDENT_3
#endif
#if GH3X2X_ALGORITHMS_MEMORY_RESIDENT < GH3X2X_ALGORITHMS_MEMORY_RESIDENT_4
#undef GH3X2X_ALGORITHMS_MEMORY_RESIDENT
#define GH3X2X_ALGORITHMS_MEMORY_RESIDENT GH3X2X_ALGORITHMS_MEMORY_RESIDENT_4
#endif

//final size
#define GH3X2X_ALGORITHMS_MEMORY_SIZE_FINAL  (((GU32)((GH3X2X_ALGORITHMS_MEMORY_RESIDENT + GH3X2X_ALGORITHMS_MEMORY_PEAK_WITHOUT_RESIDENT + GH3X2X_ALGORITHMS_MEMORY_REDUNDANCY + 3)/4))*4)
#endif  //__ALGO_RUN_SIMULTANEOUSLY_SUPPORT__

/**
 * @fn     GS8 GH3X2X_AlgoMemConfig( GU32 unMemSize)
 *
 * @brief  Config algorithm memory.
 *
 * @attention   Mem can only be static,such as global array
 *
 * @param[in]  unMemSize       memory size(unit:byte)
 *
 * @return  error code
 * @retval  #GH3X2X_RET_OK                      return successfully
 * @retval  #GH3X2X_RET_RESOURCE_ERROR          return algorithm mem config error
 */
GS8 GH3X2X_AlgoMemConfig( GU32 unMemSize);

#endif

#endif /* _GH3X2X_DEMO_ALGO_CALL_H_ */

/********END OF FILE********* Copyright (c) 2003 - 2022, Goodix Co., Ltd. ********/
